﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.minigames {
    import flash.events.*;
    import Engine.Managers.*;
    import Engine.Helpers.*;
    import flash.utils.*;
    import Classes.*;
    import Classes.util.*;
    import Classes.sim.*;
    import Modules.minigames.transactions.*;

    public class MiniGame implements IGameWorldUpdateObserver {

        private static const gremlinsMiniGame:GremlinsMiniGame = null;

        protected static var miniGame:MiniGame;

        protected const INVALID_MINI_GAME:String = "MiniGame";
        protected const MINI_GAME_CONFIG:String = "default_mini_game";
        protected const UNLIMITED_TIME:int = -1;

        protected var m_timer:Timer;
        protected var m_score:Number;
        protected var m_isActive:Boolean;

        public function MiniGame(){
            this.m_isActive = false;
            if (this.timeLimit >= 0){
                this.m_timer = new Timer(1000, 30);
                this.m_timer.addEventListener(TimerEvent.TIMER, this.updateSecond);
                this.m_timer.addEventListener(TimerEvent.TIMER_COMPLETE, this.onTimerComplete);
            };
            Global.world.addObserver(this);
        }
        public static function start(_arg1:String):Boolean{
            var _local2:Class;
            if (((!(miniGame)) || (!(miniGame.m_isActive)))){
                _local2 = (getDefinitionByName(("Modules.minigames." + _arg1)) as Class);
                miniGame = new (_local2)();
                miniGame.init();
                return (true);
            };
            return (false);
        }
        public static function getMiniGame():MiniGame{
            if (miniGame){
                return (miniGame);
            };
            return (null);
        }
        public static function end():void{
            if (miniGame){
                miniGame.onEnd();
            };
            miniGame = null;
        }
        public static function canStartMiniGame(_arg1:String):Boolean{
            var _local2:Boolean;
            var _local3:Class = (getDefinitionByName(("Modules.minigames." + _arg1)) as Class);
            if (_local3){
                _local2 = _local3.canStartMiniGame.call();
            };
            return (_local2);
        }

        public function getScore():Number{
            return (this.m_score);
        }
        protected function get timeLimit():int{
            return (this.UNLIMITED_TIME);
        }
        protected function get name():String{
            return (this.INVALID_MINI_GAME);
        }
        public function isActive():Boolean{
            return (this.m_isActive);
        }
        public function getResults():Object{
            return ({score:this.m_score});
        }
        protected function onTimerComplete(_arg1:TimerEvent):void{
            this.complete();
        }
        protected function updateSecond(_arg1:TimerEvent):void{
            Global.hud.updateMiniGame((_arg1.currentTarget as Timer).currentCount);
        }
        public function complete():void{
            this.m_isActive = false;
            GameTransactionManager.addTransaction(new TMiniGameComplete(this.name, this.getResults()));
            StatsManager.sample(100, "miniGame", "complete", this.name, String(this.m_score));
            this.onEnd();
        }
        public function init():void{
            this.m_isActive = true;
            Global.disableMenu = true;
            if (this.m_timer){
                this.m_timer.start();
            };
            this.m_score = 0;
            StatsManager.sample(100, "miniGame", "start", this.name);
        }
        public function update(_arg1:Number):void{
        }
        public function onEnd():void{
            this.m_isActive = false;
            this.m_timer.reset();
            Global.world.removeObserver(this);
            Global.disableMenu = false;
        }
        public function initialize():void{
        }
        public function cleanUp():void{
        }
        public function onGameLoaded(_arg1:Object):void{
        }
        public function onResourceChange(_arg1:MapResource, _arg2:Vector3, _arg3:Vector3):void{
        }

    }
}//package Modules.minigames 
